package com.rxh.service;

import com.rxh.exception.PayException;
import com.rxh.risk.RiskContext;
import com.rxh.risk.RiskInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 陈俊雄
 * Date: 2018/9/10
 * Time: 10:06
 * Project: Management
 * Package: com.rxh.service
 */
@Service
public class RiskAnalysisService {

    private final List<RiskInterface> riskInterfaces;

    @Autowired
    public RiskAnalysisService(List<RiskInterface> riskInterfaces) {
        this.riskInterfaces = riskInterfaces;
    }

    public void doRisk(RiskContext riskContext) throws PayException {
        List<String> risks = Arrays.asList(riskContext.getCoreAcquirer().getRisk().split(","));
        for (RiskInterface riskInterface : riskInterfaces) {
            if (risks.contains(riskInterface.getRiskName())) {
                riskInterface.analysis(riskContext);
            }
        }
    }
}
